/**
 * Created by kinghackers on 2016/12/1.
 */
$(document).ready(function(){
    var config = {
        language: 'zh',
        uploadUrl: '/fileupload/upload',
        deleteUrl: "/fileupload/delete",
        multiple:true,
        initialPreview:[
            '/upload/formidable/file/1480753124700_2014最新全国省市区县_行政区划__一览表.xls',
            '/upload/formidable/audio/1480745436493_逆流成河.mp3',
            '/upload/formidable/image/1480745436386_4.jpg'
        ]
    };



    $("#uponly").fileinput({
        language: config.language,
        uploadUrl: config.uploadUrl,
        multiple: config.multiple,
        allowedFileExtensions : ['jpg', 'png','gif'],
        initialCaption: "只能上传一张图片哦亲"
    }).on("fileuploaded", function(event, data, previewId, index) {
        console.info(data); //返回的结果保存在data.response中
    });

    $("#myfile").fileinput({
        language: config.language,
        uploadUrl: config.uploadUrl,
        deleteUrl: config.deleteUrl,
        multiple: config.multiple,
        initialCaption: "可以上传任意类型文件"
    }).on("fileuploaded", function(event, data, previewId, index) {
        console.info(data); //返回的结果保存在data.response中
        console.info(previewId);

        //TODO 临时上传的文件怎么删除（物理真实删除）还没研究好， #input-24中预加载的文件支持删除
        // $("#myfile").fileinput.initialPreview = [data.response.path];
        // $("#myfile").fileinput.initialPreviewConfig = [{caption: data.response.name, type: "other"
        //         , size: data.response.size, key: data.response.path, url: config.deleteUrl}];
    });

    $("#input-24").fileinput({
        language: config.language,
        uploadUrl: config.uploadUrl,
        multiple: config.multiple,
        initialPreview: config.initialPreview,
        initialPreviewAsData: true,
        initialPreviewConfig: [
            {caption: "2014最新全国省市区县_行政区划__一览表.xls", type: "other", filetype: "application/msexcel", size: 512000, key: config.initialPreview[0]},
            {caption: "逆流成河.mp3", type: "audio", filetype: "audio/mp3", size: 1230848, key: config.initialPreview[1]},
            {caption: "瞅你咋的.jpg", size: 1218822, width: "120px", key: config.initialPreview[2]}
        ],
        deleteUrl: config.deleteUrl,
        overwriteInitial: false,
        maxFileSize: 100,
        initialCaption: "选择图片上传"
    });
});